<template>
  <view class="container">
    <!-- 顶部导航栏 -->
    <view class="nav-bar">
      <view class="left" @click="goBack">
        <image class="back-icon" src="/static/back-icon.png"></image>
      </view>
      <text class="nav-title">材料入库</text>
    </view>
    
    <!-- 步骤条 -->
    <view class="step-bar">
      <view class="step-group">
        <!-- 步骤1 -->
        <view class="step-item active">
          <view class="step-icon">
            <text class="step-number">1</text>
          </view>
          <text class="step-text active-text">添加入库单</text>
        </view>
        
        <!-- 连接线1 -->
        <view class="step-line">
          <view v-for="(item, index) in 15" :key="index" class="line-segment active-line"></view>
          <view class="line-arrow active-arrow"></view>
        </view>
        
        <!-- 步骤2 -->
        <view class="step-item">
          <view class="step-icon">
            <text class="step-number">2</text>
          </view>
          <text class="step-text">绑定材料</text>
        </view>
        
        <!-- 连接线2 -->
        <view class="step-line">
          <view v-for="(index) in 15" :key="index" class="line-segment"></view>
          <view class="line-arrow"></view>
        </view>
        
        <!-- 步骤3 -->
        <view class="step-item">
          <view class="step-icon">
            <text class="step-number">3</text>
          </view>
          <text class="step-text">入库成功</text>
        </view>
      </view>
    </view>
    
    <!-- 表单内容 -->
    <view class="form-content" v-if="actionIndex===0">
      <!-- 入库编号 -->
      <view class="form-item">
        <view class="form-label">
          <text class="label-text">入库编号</text>
        </view>
        <view class="form-input">
          <text class="input-text">RK-000027</text>
        </view>
      </view>
      
      <!-- 计量周期 -->
      <view class="form-item">
        <view class="form-label">
          <text class="label-text">计量周期</text>
        </view>
        <view class="form-input" @click="selectPeriod">
          <text class="input-text" :class="{ placeholder: !formData.period }">{{ formData.period || '请选择' }}</text>
        </view>
      </view>
      
      <!-- 供应商 -->
      <view class="form-item">
        <view class="form-label">
          <text class="label-text">供应商</text>
        </view>
        <view class="form-input" @click="selectSupplier">
          <text class="input-text" :class="{ placeholder: !formData.supplier }">{{ formData.supplier || '请选择' }}</text>
        </view>
      </view>
    </view>
	
	<!-- 绑定材料 -->
	<view class="materials-form" v-if="actionIndex===1">
		<view class="selector">
			<view class="selector-title">
				材料模板
			</view>
			<view class="selector-content" @click="showOutPicker=true">
				请选择
			</view>
		</view>
		<view class="materials">
			<view class="materials-title">
				选择材料
			</view>
			<scroll-view scroll-y class="materials-from">
				<view class="materials-item" v-for="i in 5">
					<view class="materials-checkbox">
							<checkbox />
					</view>
					<image class="materials-img" src="/static/logo.png" mode=""></image>
					<view class="description">
						<view class="materials-encoding">
							CL-000064
						</view>
						<view class="description-content">
							混凝土 | C25  | m³
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
	<view class="management" v-if="actionIndex===2">
		<image class="succeed-img" src="/static/succeed-img.png" mode=""></image>
		<text class="reminder">材料入库成功</text>
		<view class="look-but but">
			查看入库单
		</view>
		<view class="continue-but but">
			继续入库
		</view>
	</view>
	
    
    <!-- 底部按钮 -->
    <view class="bottom-bar" v-show="actionIndex<=1">
      <view class="next-button" @click="goToNextStep">
        <text class="button-text">下一步</text>
      </view>
    </view>

    <!-- 底部弹出层 -->
    <view v-if="showOutPicker" class="picker-container">
      <view class="picker-mask" @click="closeOutPicker"></view>
      <view class="picker-content">
        <view class="picker-header">
          <text class="picker-cancel" @click="closeOutPicker">取消</text>
          <text class="picker-title">选择模板</text>
          <text class="picker-confirm" @click="confirmOut">确定</text>
        </view>
        <view class="form-head">
          <view class="form-select">
            选择
          </view>
          <view class="form-encoding">
            编码
          </view>
          <view class="from-name">
            名称
          </view>
          <view class="from-specification">
            规格
          </view>
        </view>
        <scroll-view scroll-y class="picker-list">
          <view class="picker-item" v-for="(item, index) in outOptions" :key="index" 
                :class="{ 'selected': selectedOutOption === item.value,'from-double':index%2===1 }"
                @click="selectOutOption(item.value)">
            <view class="form-select">
              <checkbox/>
            </view>
            <view class="form-encoding">
              CL-0000552
            </view>
            <view class="from-name">
              沥青
            </view>
            <view class="from-specification">
              90#
            </view>
          </view>
        </scroll-view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
	  actionIndex:1,
      formData: {
        code: 'RK-000027',
        period: '',
        supplier: '',
      },
	  // 添加材料数据
	  // 弹出框
	  showOutPicker:false,
	  outOptions: [
	    { label: '西藏于睿建筑劳务公司', value: 'company1' },
	    { label: '西藏于睿建筑劳务公司', value: 'company2' },
	    { label: '西藏于睿建筑劳务公司', value: 'company3' },
	    { label: '西藏于睿建筑劳务公司', value: 'company1' },
	    { label: '西藏于睿建筑劳务公司', value: 'company2' },
	    { label: '西藏于睿建筑劳务公司', value: 'company3' },
		{ label: '西藏于睿建筑劳务公司', value: 'company1' },
		{ label: '西藏于睿建筑劳务公司', value: 'company2' },
		{ label: '西藏于睿建筑劳务公司', value: 'company3' },
		{ label: '西藏于睿建筑劳务公司', value: 'company1' },
		{ label: '西藏于睿建筑劳务公司', value: 'company2' },
	  ],
	  selectedOutOption:''
    }
  },
  methods: {
    goBack() {
      uni.navigateBack();
    },
    selectPeriod() {
      uni.showActionSheet({
        itemList: ['第1期', '第2期', '第3期'],
        success: (res) => {
          const periods = ['第1期', '第2期', '第3期'];
          this.formData.period = periods[res.tapIndex];
        }
      });
    },
    selectSupplier() {
      uni.showActionSheet({
        itemList: ['西藏交投工贸有限公司', '陕西建工集团有限公司', '中国电建集团有限公司'],
        success: (res) => {
          const suppliers = ['西藏交投工贸有限公司', '陕西建工集团有限公司', '中国电建集团有限公司'];
          this.formData.supplier = suppliers[res.tapIndex];
        }
      });
    },
    goToNextStep() {
      if(this.actionIndex===0){
		  if (!this.formData.period || !this.formData.supplier) {
		    uni.showToast({
		      title: '请完善信息',
		      icon: 'none'
		    });
		    return;
		  }
	  }
      
      // 保存入库单信息，进入下一步（绑定材料）
      // uni.navigateTo({
      //   url: '/pages/material/add-material?code=' + this.formData.code
      // });
	  this.actionIndex++
    },
	handleOutClick(){
		this.showOutPicker =true ;
	},
	closeOutPicker() {
	  this.showOutPicker = false;
	  this.selectedOutOption = '';
	},
	confirmOut(){
		this.showOutPicker = false;
	},
	selectOutOption(value) {
	  this.selectedOutOption = value;
	},
  }
}
</script>

<style>
.container {
  flex: 1;
  background-color: #E6EAF3;
}

.nav-bar {
  height: 88px;
  background: linear-gradient(103deg, #4980FF -4%, #2B6BFF 99%);
  padding-top: 44px;
  padding-left: 15px;
  padding-right: 15px;
  flex-direction: row;
  align-items: center;
  position: relative;
}

.left {
  position: absolute;
  left: 15px;
  height: 24px;
  width: 24px;
  justify-content: center;
  align-items: center;
}

.back-icon {
  width: 24px;
  height: 24px;
}

.nav-title {
  font-size: 18px;
  color: #FFFFFF;
  font-weight: 500;
  margin-left: 24px;
}

.step-bar {
  height: 82px;
  background-color: #FFFFFF;
  justify-content: center;
  align-items: center;
}

.step-group {
  width: 271px;
  height: 40px;
  flex-direction: row;
  align-items: center;
}

.step-item {
  width: 48px;
  height: 40px;
  align-items: center;
}

.step-icon {
  width: 24px;
  height: 20px;
  background-color: #666666;
  border-radius: 4px;
  justify-content: center;
  align-items: center;
  margin-bottom: 8px;
}

.step-item.active .step-icon {
  background-color: #4980FF;
}

.step-number {
  font-size: 12px;
  color: #FFFFFF;
  font-weight: 500;
}

.step-text {
  font-size: 12px;
  color: #666666;
}

.active-text {
  color: #4980FF;
}

.step-line {
  width: 69px;
  height: 1px;
  flex-direction: row;
  align-items: center;
  margin-top: -20px;
}

.line-segment {
  width: 2px;
  height: 2px;
  background-color: #666666;
  margin-right: 2px;
}

.line-segment.active-line {
  background-color: #4980FF;
}

.line-arrow {
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 5px 0 5px 8px;
  border-color: transparent transparent transparent #666666;
}

.line-arrow.active-arrow {
  border-color: transparent transparent transparent #4980FF;
}

.form-content {
  margin-top: 10px;
  background-color: #FFFFFF;
}

.form-item {
  height: 56px;
  flex-direction: row;
  align-items: center;
  padding: 0 16px;
  border-bottom-width: 1px;
  border-bottom-color: #F5F7FA;
}

.form-label {
  width: 81px;
}

.label-text {
  font-size: 16px;
  color: #242731;
}

.form-input {
  flex: 1;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  margin-left: 16px;
}

.input-text {
  font-size: 16px;
  color: #242731;
}

.placeholder {
  color: #86909C;
}

.materials-form{
	/* background-color: #FFFFFF; */
	margin-top: 20rpx;
}
.selector{
	width: 750rpx;
	/* height: 112rpx; */
	padding: 0 32rpx;
	flex-direction: row;
	font-family: PingFang SC;
	font-size: 32rpx;
	font-weight: normal;
	line-height: 112rpx;
	background-color: #FFFFFF;
}

.selector-title{
	width: 162rpx;
	height: 112rpx;
	
}
.selector-content{
	flex: 1;
	color: rgba(29, 33, 41, 0.65);
}

.materials{
	width: 670rpx;
	height: 944rpx;
	margin: 22rpx 40rpx;
	border-radius: 20rpx;
	color: #666666;
	background-color: #FFFFFF;
}

.materials-title{
	height: 100rpx;
	line-height: 100rpx;
	padding-left: 40rpx;
	font-family: 思源黑体;
	font-size: 24rpx;
	font-weight: normal;
}

.materials-item{
	flex-direction: row;
	padding: 20rpx 20rpx 20rpx 30rpx;
}

.materials-checkbox{
	align-items: center;
	justify-content: center;
	margin-right: 24rpx;
}
.materials-img{
	width: 120rpx;
	height: 120rpx;
	margin-right: 24rpx;
}

.description{
	width: 220rpx;
}
.materials-encoding{
	margin-bottom: 12rpx;
	font-family: 思源黑体;
	font-size: 28rpx;
	color: #333333;
}
.description-content{
	font-size: 24rpx
}

.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 94px;
  justify-content: center;
  align-items: center;
  padding: 10px 30px;
}

.next-button {
  width: 315px;
  height: 44px;
  background-color: #E8F3FF;
  border-radius: 22px;
  justify-content: center;
  align-items: center;
}

.button-text {
  font-size: 15px;
  color: #165DFF;
}
/* 修改底部弹出层部分 */
	.picker-container {
	  position: fixed;
	  left: 0;
	  right: 0;
	  bottom: 0;
	  top: 0;
	  z-index: 100;
	}
	
	.picker-mask {
	  position: absolute;
	  top: 0;
	  left: 0;
	  right: 0;
	  bottom: 0;
	  background-color: rgba(0, 0, 0, 0.4);
	}
	
	.picker-content {
	  position: absolute;
	  left: 0;
	  right: 0;
	  bottom: 0;
	  background-color: #FFFFFF;
	  border-top-left-radius: 16px;
	  border-top-right-radius: 16px;
	}
	
	.picker-header {
	  height: 53px;
	  flex-direction: row;
	  justify-content: space-between;
	  align-items: center;
	  padding: 0 16px;
	  border-bottom-width: 1px;
	  border-bottom-color: #EEF2F9;
	  margin-bottom: 30rpx;
	}
	
	.picker-title {
	  font-size: 16px;
	  color: #1D2129;
	  font-weight: 400;
	}
	
	.picker-cancel, .picker-confirm {
	  font-size: 16px;
	}
	
	.picker-cancel {
	  color: #86909C;
	}
	
	.picker-confirm {
	  color: #165DFF;
	}
	
	.form-head{
		flex-direction: row;
		margin: 0 23rpx;
		height: 56rpx;
		font-size: 24rpx;
		color: #FFFFFF;
		line-height: 56rpx;
		background-color: #4980FF;
	}
	.form-select{
		width: 88rpx;
		padding-left: 16rpx;
	}
	.form-encoding{
		width: 276rpx;
		padding-left: 16rpx;
	}
	.from-name{
		width: 172rpx;
		padding-left: 16rpx;
	}
	.from-specification{
		padding-left: 16rpx;
	}
	.picker-list {
	  padding: 24rpx 0;
	  padding-top: 0;
	  max-height: 350rpx;
	  margin-bottom: 12px;
	  /* overflow: scroll; */
	}
	
	.picker-item {
	  height: 56rpx;
	  flex-direction: row;
	  /* justify-content: center; */
	  align-items: center;
	  padding: 0 16px;
	}
	.from-double{
		background: rgba(73, 128, 255, 0.06);
	}
	.management{
		align-items: center;
	}
	.succeed-img{
		margin-top: 148rpx;
		width: 240rpx;
		height: 220rpx;
	}
	.reminder{
		margin: 40rpx 0rpx;
		font-family: 思源黑体;
		font-size: 28rpx;
		font-weight: normal;
		
	}
	.but{
		width: 480rpx;
		height: 80rpx;
		font-family: 思源黑体;
		font-size: 14px;
		text-align: center;
		font-weight: normal;
		line-height: 80rpx;
		border-radius: 80rpx;
		border: 1px solid #235EFF;
	}
	.look-but{
		color: #235EFF;
		margin-bottom: 40rpx;
	}
	.continue-but{
		color: #FFFFFF;
		background-color: #235EFF;
	}
	/* 移除选中状态相关样式 */
	.selected-icon {
	  display: none;
	}
</style> 